import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import os

# 打开浏览器
driver = webdriver.Chrome()
driver.maximize_window()

# 获取本地地址
url = 'file:///' + os.path.abspath('html') + '/注册a.html'
driver.get(url)

# 准备数据
userinfo = {
    'userA' : 'root' ,
    'passwordA' : '123456',
    'telA' : '13552193366',
    'emailA' : '619469656@qq.com'
}
#  TODO 1 定位注册A
# 输入id
driver.find_element(By.ID, 'userA').send_keys(userinfo['userA'])
# 输入密码
driver.find_element(By.ID, 'passwordA').send_keys(userinfo['passwordA'])
# 输入电话
driver.find_element(By.ID, 'telA').send_keys(userinfo['telA'])
# 输入邮箱
driver.find_element(By.ID, 'emailA').send_keys(userinfo['emailA'])

# 点击按钮并注册
driver.find_element(By.XPATH,'//*[@id="zc"]/fieldset/button').click()
time.sleep(2)
# 退出浏览器
time.sleep(2)
driver.quit()

# TODO 2 定位注册B
# 输入id
driver.find_element(By.ID, 'userB').send_keys(userinfo['userB'])
# 输入密码
driver.find_element(By.ID, 'passwordB').send_keys(userinfo['passwordB'])
# 输入电话
driver.find_element(By.ID, 'telB').send_keys(userinfo['telB'])
# 输入邮箱
driver.find_element(By.ID, 'emailB').send_keys(userinfo['emailB'])

# 点击按钮并注册
driver.find_element(By.XPATH,'//*[@id="zc"]/fieldset/button').click()
time.sleep(2)

# 退出浏览器
time.sleep(2)
driver.quit()

# TODO 3 定位注册
# 输入id
driver.find_element(By.ID, 'user').send_keys(userinfo['user'])
# 输入密码
driver.find_element(By.ID, 'password').send_keys(userinfo['password'])
# 输入电话
driver.find_element(By.ID, 'telB').send_keys(userinfo['tel'])
# 输入邮箱
driver.find_element(By.ID, 'email').send_keys(userinfo['email'])

# 点击按钮并注册
driver.find_element(By.XPATH,'//*[@id="zc"]/fieldset/button').click()
time.sleep(2)

# 退出浏览器
time.sleep(2)
driver.quit()
